package com.cxh.androidmedia.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cxh.androidmedia.R;
import com.cxh.androidmedia.adapter.BeautyListRvAdapter;
import com.cxh.androidmedia.common.CommonBaseRVHolder;
import com.cxh.androidmedia.common.CommonBaseRvAdapter;
import com.cxh.androidmedia.render_old.bean.BeautyBean;
import com.cxh.androidmedia.render_old.bean.BeautyParams;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Cxh
 * Time : 2020-09-17  21:40
 * Desc :
 */
public class FilterSetDialog extends Dialog {

    @BindView(R.id.iv_title)
    TextView mTvTitle;

    @BindView(R.id.rv_beauty_list)
    RecyclerView mRvBeautyList;

    private BeautyListRvAdapter mAdapter;
    private OnFilterChangedCallback mBeautyCallback;

    public FilterSetDialog(@NonNull Context context) {
        super(context, R.style.CommonBottomSheet);
        setContentView(R.layout.dilaog_filter_set_layout);
        ButterKnife.bind(this);

        Window window = getWindow();
        if (null != window) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.gravity = Gravity.BOTTOM;
            window.setAttributes(params);
        }
        setCancelable(true);
        setCanceledOnTouchOutside(true);

        mAdapter = new BeautyListRvAdapter(context);
        mRvBeautyList.setLayoutManager(new GridLayoutManager(context, 5));
        mRvBeautyList.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new CommonBaseRvAdapter.OnItemClickListener<BeautyBean>() {
            @Override
            public void onItemClick(CommonBaseRVHolder holder, BeautyBean data, int position) {
                mAdapter.setCurrentBeauty(position);

                if (null != mBeautyCallback) {
                    mBeautyCallback.onFilterChanged(data);
                }
            }
        });
        mAdapter.setList(BeautyParams.getFilterBeans());

    }

    public void setBeautyCallback(OnFilterChangedCallback beautyCallback) {
        mBeautyCallback = beautyCallback;
    }

    public interface OnFilterChangedCallback {
        void onFilterChanged(BeautyBean data);
    }
}
